package com.yourcompany.web.controller;

import cn.dev33.satoken.util.SaResult;
import com.yourcompany.api.dto.CreditActivateDTO;
import com.yourcompany.api.dto.CreditPayDTO;
import com.yourcompany.api.dto.CreditRepayDTO;
import com.yourcompany.api.service.CreditPayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "先充后付")
@RestController
@RequestMapping("/credit-pay")
public class CreditPayController {
    
    @Autowired
    private CreditPayService creditPayService;
    
    @Operation(summary = "开通先充后付")
    @PostMapping("/activate")
    public SaResult activate(@RequestBody CreditActivateDTO activateDTO) {
        creditPayService.activate(activateDTO);
        return SaResult.ok();
    }
    
    @Operation(summary = "使用先充后付支付")
    @PostMapping("/pay")
    public SaResult pay(@RequestBody CreditPayDTO payDTO) {
        String result = creditPayService.pay(payDTO);
        return SaResult.data(result);
    }
    
    @Operation(summary = "还款")
    @PostMapping("/repay")
    public SaResult repay(@RequestBody CreditRepayDTO repayDTO) {
        String result = creditPayService.repay(repayDTO);
        return SaResult.data(result);
    }
    
    @Operation(summary = "获取可用额度")
    @GetMapping("/available-credit/{userId}")
    public SaResult getAvailableCredit(@PathVariable Long userId) {
        BigDecimal credit = creditPayService.getAvailableCredit(userId);
        return SaResult.data(credit);
    }
} 